package net.adetech.cjg.innerservice.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.adetech.cjg.innerservice.entity.*;
import net.adetech.cjg.innerservice.mapper.FrmCodeDao;
import net.adetech.cjg.innerservice.mapper.TjDao;
import net.adetech.cjg.innerservice.mapper.ZdryjlDao;
import net.adetech.cjg.innerservice.utils.SixInOneUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.websocket.server.PathParam;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
public class InfoController {


    @Value("${tfws.url}")
    private String baseUrl;

    @Value("${pvs_verify.url}")
    private String pvsVerifyUrl;

    @Value("${app.domain}")
    private String appDomain;


//    private String baseUrl = "http://10.231.49.65:8090";


    @Autowired
    FrmCodeDao frmCodeDao;


    @Autowired
    ZdryjlDao zdryjlDao;

    @Autowired
    SixInOneUtils sixInOneUtils;


    private static Map<String, Map<String, String>> codeMapMap = new HashMap<>();

    private String getCodeName(String xtlb, String dmlb, String code) {
        String lb = xtlb + "_" + dmlb;
        Map<String, String> codeMap = codeMapMap.get(lb);
        if (codeMap == null) {
            List<FrmCode> frmCodeList = frmCodeDao.getFrmCodeList(dmlb, xtlb);
            codeMap = new HashMap<>();
            if (frmCodeList != null && frmCodeList.size() > 0) {
                for (FrmCode frmCode : frmCodeList
                ) {
                    codeMap.put(frmCode.getDmz(), frmCode.getDmsm1());
                }
            }
            codeMapMap.put(lb, codeMap);
        }
        String result = codeMap.get(code);
        if (result == null) {
            result = "";
        }
        return result;
    }


    @RequestMapping(value = "/cjg/getInfo", produces = "application/json")
    public String getInfo( String idNumber) {
        if("wf".equals(appDomain))
        {
            return getInfoWf(idNumber);
        }
        if("yt".equals(appDomain))
        {
            return getInfoYt(idNumber);
        }
        if("qd".equals(appDomain))
        {
            return getInfoQd(idNumber);
        }

        return null;
    }

    //烟台
    public String getInfoYt( String idNumber) {
        idNumber = idNumber.toUpperCase();
        AllInfo allInfo = new AllInfo();
        JSONObject manJson = this.getManInfoYt(idNumber);
//        manJson = new JSONObject();
        if (manJson != null && manJson.getString("xm") != null) {
            ManInfo manInfo = new ManInfo();
            manInfo.setXm(manJson.getString("xm"));
            manInfo.setXb(manJson.getString("xb"));
            manInfo.setSfzmhm(idNumber);
            manInfo.setCsrq(manJson.getString("csrq"));
            manInfo.setLxzsxxdz(manJson.getString("lxzsxxdz"));
            manInfo.setSjhm(manJson.getString("sjhm"));
            manInfo.setFzjg(manJson.getString("fzjg"));
            manInfo.setJzqx(manJson.getString("jzqx"));
            manInfo.setYxqs(manJson.getString("yxqs"));
            manInfo.setYxqz(manJson.getString("yxqz"));
            manInfo.setZjcx(manJson.getString("zjcx"));
            manInfo.setCclzrq(manJson.getString("cclzrq"));
            manInfo.setGj(manJson.getString("gj"));
            manInfo.setLxzsyzbm(manJson.getString("lxzsyzbm"));
            manInfo.setLxdh(manJson.getString("lxdh"));
            manInfo.setDzyx(manJson.getString("dzyx"));
            manInfo.setLjjf(manJson.getString("ljjf"));
            manInfo.setZt(manJson.getString("zt"));

            manInfo.setLxzsxzqh(manJson.getString("lxzsxzqh"));


            manInfo.setDjzsxzqh(manJson.getString("djzsxzqh"));
            manInfo.setDjzsxxdz(manJson.getString("djzsxxdz"));
            manInfo.setDjzsyzbm(manJson.getString("djzsyzbm"));


            manInfo.setZtmc(getManZt(manInfo.getZt()));
            manInfo.setDabh(manJson.getString("dabh"));
            manInfo.setXbmc(getCodeName("00", "0035", manInfo.getXb()));
            allInfo.setManInfo(manInfo);
        } else {
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("sfzmhm", idNumber);
            manJson = sixInOneUtils.call(paramsJson, "02C26");
            ManInfo manInfo = new ManInfo();
            manInfo.setXm(manJson.getString("xm"));
            manInfo.setXb(manJson.getString("xb"));
            manInfo.setSfzmhm(idNumber);
            manInfo.setCsrq(manJson.getString("csrq"));
            manInfo.setLxzsxxdz(manJson.getString("lxzsxxdz"));
            manInfo.setSjhm(manJson.getString("sjhm"));
            manInfo.setFzjg(manJson.getString("fzjg"));
            manInfo.setJzqx(manJson.getString("jzqx"));
            manInfo.setYxqs(manJson.getString("yxqs"));
            manInfo.setYxqz(manJson.getString("yxqz"));
            manInfo.setZjcx(manJson.getString("zjcx"));
            manInfo.setCclzrq(manJson.getString("cclzrq"));
            manInfo.setGj(manJson.getString("gj"));
            manInfo.setLxzsyzbm(manJson.getString("lxzsyzbm"));
            manInfo.setLxdh(manJson.getString("lxdh"));
            manInfo.setDzyx(manJson.getString("dzyx"));
            manInfo.setLjjf(manJson.getString("ljjf"));
            manInfo.setZt(manJson.getString("zt"));
            manInfo.setLxzsxzqh(manJson.getString("lxzsxzqh"));

            manInfo.setDjzsxzqh(manJson.getString("djzsxzqh"));
            manInfo.setDjzsxxdz(manJson.getString("djzsxxdz"));
            manInfo.setDjzsyzbm(manJson.getString("djzsyzbm"));
            manInfo.setZtmc(getManZt(manInfo.getZt()));
            manInfo.setDabh(manJson.getString("dabh"));
            manInfo.setXbmc(getCodeName("00", "0035", manInfo.getXb()));
            allInfo.setManInfo(manInfo);
        }

        JSONArray carListJson = this.getCarListYt(idNumber);
        if (carListJson != null && carListJson.size() > 0) {
            for (int i = 0; i < carListJson.size(); i++) {
                JSONObject tempCarObject = carListJson.getJSONObject(i);
                String carNumber = tempCarObject.getString("hphm");
                String carNumberType = tempCarObject.getString("hpzl");
                JSONObject carJson = this.getCarInfo(carNumber, carNumberType);
                if (carJson != null) {
                    CarInfo carInfo = transCarInfo(carJson, carNumber, carNumberType);
                    allInfo.getCarInfoList().add(carInfo);
                }


            }

        }
        return JSONObject.toJSONString(allInfo);
    }

    //潍坊
    public String getInfoWf(String idNumber) {
        idNumber = idNumber.toUpperCase();
        AllInfo allInfo = new AllInfo();

        JSONObject paramsJson = new JSONObject();
        paramsJson.put("sfzmhm", idNumber);
        JSONObject manJson = sixInOneUtils.call(paramsJson, "02C06");
        ManInfo manInfo = new ManInfo();
        manInfo.setXm(manJson.getString("xm"));
        manInfo.setXb(manJson.getString("xb"));
        manInfo.setSfzmhm(idNumber);
        manInfo.setCsrq(manJson.getString("csrq"));
        manInfo.setLxzsxxdz(manJson.getString("lxzsxxdz"));
        manInfo.setSjhm(manJson.getString("sjhm"));
        manInfo.setFzjg(manJson.getString("fzjg"));
        manInfo.setJzqx(manJson.getString("jzqx"));
        manInfo.setYxqs(manJson.getString("yxqs"));
        manInfo.setYxqz(manJson.getString("yxqz"));
        manInfo.setZjcx(manJson.getString("zjcx"));
        manInfo.setCclzrq(manJson.getString("cclzrq"));
        manInfo.setGj(manJson.getString("gj"));
        manInfo.setLxzsyzbm(manJson.getString("lxzsyzbm"));
        manInfo.setLxdh(manJson.getString("lxdh"));
        manInfo.setDzyx(manJson.getString("dzyx"));
        manInfo.setLjjf(manJson.getString("ljjf"));
        manInfo.setZt(manJson.getString("zt"));
        manInfo.setLxzsxzqh(manJson.getString("lxzsxzqh"));

        manInfo.setDjzsxzqh(manJson.getString("djzsxzqh"));
        manInfo.setDjzsxxdz(manJson.getString("djzsxxdz"));
        manInfo.setDjzsyzbm(manJson.getString("djzsyzbm"));
        manInfo.setZtmc(getManZt(manInfo.getZt()));
        manInfo.setDabh(manJson.getString("dabh"));
        manInfo.setXbmc(getCodeName("00", "0035", manInfo.getXb()));
        allInfo.setManInfo(manInfo);

        return JSONObject.toJSONString(allInfo);
    }

    //青岛
    public String getInfoQd(String idNumber) {
        idNumber = idNumber.toUpperCase();
        AllInfo allInfo = new AllInfo();
        JSONObject manJson = this.getManInfoQd(idNumber);
//        manJson = new JSONObject();
        if (manJson != null && manJson.getString("xm") != null) {
            ManInfo manInfo = new ManInfo();
            manInfo.setXm(manJson.getString("xm"));
            manInfo.setXb(manJson.getString("xb"));
            manInfo.setSfzmhm(idNumber);
            manInfo.setCsrq(manJson.getString("csrq"));
            manInfo.setLxzsxxdz(manJson.getString("lxzsxxdz"));
            manInfo.setSjhm(manJson.getString("sjhm"));
            manInfo.setFzjg(manJson.getString("fzjg"));
            manInfo.setJzqx(manJson.getString("jzqx"));
            manInfo.setYxqs(manJson.getString("yxqs"));
            manInfo.setYxqz(manJson.getString("yxqz"));
            manInfo.setZjcx(manJson.getString("zjcx"));
            manInfo.setCclzrq(manJson.getString("cclzrq"));
            manInfo.setGj(manJson.getString("gj"));
            manInfo.setLxzsyzbm(manJson.getString("lxzsyzbm"));
            manInfo.setLxdh(manJson.getString("lxdh"));
            manInfo.setDzyx(manJson.getString("dzyx"));
            manInfo.setLjjf(manJson.getString("ljjf"));
            manInfo.setZt(manJson.getString("zt"));

            manInfo.setLxzsxzqh(manJson.getString("lxzsxzqh"));


            manInfo.setDjzsxzqh(manJson.getString("djzsxzqh"));
            manInfo.setDjzsxxdz(manJson.getString("djzsxxdz"));
            manInfo.setDjzsyzbm(manJson.getString("djzsyzbm"));


            manInfo.setZtmc(getManZt(manInfo.getZt()));
            manInfo.setDabh(manJson.getString("dabh"));
            manInfo.setXbmc(getCodeName("00", "0035", manInfo.getXb()));
            allInfo.setManInfo(manInfo);
        } else {
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("sfzmhm", idNumber);
            manJson = sixInOneUtils.call(paramsJson, "02C26");
            ManInfo manInfo = new ManInfo();
            manInfo.setXm(manJson.getString("xm"));
            manInfo.setXb(manJson.getString("xb"));
            manInfo.setSfzmhm(idNumber);
            manInfo.setCsrq(manJson.getString("csrq"));
            manInfo.setLxzsxxdz(manJson.getString("lxzsxxdz"));
            manInfo.setSjhm(manJson.getString("sjhm"));
            manInfo.setFzjg(manJson.getString("fzjg"));
            manInfo.setJzqx(manJson.getString("jzqx"));
            manInfo.setYxqs(manJson.getString("yxqs"));
            manInfo.setYxqz(manJson.getString("yxqz"));
            manInfo.setZjcx(manJson.getString("zjcx"));
            manInfo.setCclzrq(manJson.getString("cclzrq"));
            manInfo.setGj(manJson.getString("gj"));
            manInfo.setLxzsyzbm(manJson.getString("lxzsyzbm"));
            manInfo.setLxdh(manJson.getString("lxdh"));
            manInfo.setDzyx(manJson.getString("dzyx"));
            manInfo.setLjjf(manJson.getString("ljjf"));
            manInfo.setZt(manJson.getString("zt"));
            manInfo.setLxzsxzqh(manJson.getString("lxzsxzqh"));

            manInfo.setDjzsxzqh(manJson.getString("djzsxzqh"));
            manInfo.setDjzsxxdz(manJson.getString("djzsxxdz"));
            manInfo.setDjzsyzbm(manJson.getString("djzsyzbm"));
            manInfo.setZtmc(getManZt(manInfo.getZt()));
            manInfo.setDabh(manJson.getString("dabh"));
            manInfo.setXbmc(getCodeName("00", "0035", manInfo.getXb()));
            allInfo.setManInfo(manInfo);
        }

        JSONArray carListJson = this.getCarListQd(idNumber);
        if (carListJson != null && carListJson.size() > 0) {
            for (int i = 0; i < carListJson.size(); i++) {
                JSONObject tempCarObject = carListJson.getJSONObject(i);
                String carNumber = tempCarObject.getString("hphm");
                String carNumberType = tempCarObject.getString("hpzl");
                JSONObject carJson = this.getCarInfo(carNumber, carNumberType);
                if (carJson != null) {
                    CarInfo carInfo = transCarInfo(carJson, carNumber, carNumberType);
                    allInfo.getCarInfoList().add(carInfo);
                }


            }

        }
        return JSONObject.toJSONString(allInfo);
    }


    @RequestMapping(value = "/cjg/carInfo", produces = "application/json")
    public String carInfo(String hphm, String hpzl) {
        hphm = hphm.toUpperCase();
        JSONObject carJson = getCarInfo(hphm, hpzl);
        CarInfo carInfo = transCarInfo(carJson, hphm, hpzl);

        try {
            int today = Integer.parseInt(new SimpleDateFormat("yyyyMMdd").format(new Date()));
            int bxzzrq = Integer.parseInt(carInfo.getBxzzrq());
            if(today>bxzzrq)
            {
                carInfo.setBxzzrq("");
            }
        }catch (Exception e)
        {
            e.printStackTrace();
        }

        return JSONObject.toJSONString(carInfo);
    }

    private CarInfo transCarInfo(JSONObject carJson, String carNumber, String carNumberType) {

        CarInfo carInfo = null;
        {
            if (carJson != null) {
                carInfo = new CarInfo();

                carInfo.setHphm(carNumber);
                carInfo.setHpzl(carNumberType);
                carInfo.setHpzlmc(getCodeName("00", "1007", carNumberType));
                carInfo.setClsbdh(carJson.getString("clsbdh"));
                carInfo.setFdjh(carJson.getString("dfjh"));
                carInfo.setFzjg(carJson.getString("fzjg"));
                carInfo.setCllx(carJson.getString("cllx"));
                carInfo.setClpp1(carJson.getString("clpp1"));
                carInfo.setClxh(carJson.getString("clxh"));
                carInfo.setCsys(carJson.getString("csys"));
                carInfo.setCsysmc(getCodeName("00", "1008", carInfo.getCsys()));
                carInfo.setClly(carJson.getString("clly"));
                carInfo.setDybj(carJson.getString("dybj"));
                carInfo.setClyt(carJson.getString("clyt"));
                carInfo.setSyxz(carJson.getString("syxz"));
                carInfo.setDjrq(carJson.getString("djrq"));
                carInfo.setZt(carJson.getString("zt"));
                carInfo.setSjhm(carJson.getString("sjhm"));
                carInfo.setSfzmhm(carJson.getString("sfzmhm"));
                carInfo.setYzbm(carJson.getString("yzbm1"));
                carInfo.setBxzzrq(carJson.getString("bxzzrq"));
                if (carJson.getString("zsxxdz")!=null)
                {
                    carInfo.setZsxxdz(carJson.getString("zsxxdz"));

                }
                else if (carJson.getString("zzxxdz")!=null)
                {
                    carInfo.setZsxxdz(carJson.getString("zzxxdz"));

                }

                carInfo.setLxdh(carJson.getString("lxdh"));
                carInfo.setZtmc(getCarZt(carInfo.getZt()));
                carInfo.setCllxmc(getCodeName("00", "1004", carInfo.getCllx()));
                carInfo.setSyxz(carJson.getString("syxz"));
                carInfo.setSyr(carJson.getString("syr"));
                carInfo.setXh(carJson.getString("xh"));
                carInfo.setGlbm(carJson.getString("glbm"));
                carInfo.setBxzzrq(carJson.getString("bxzzrq"));
            }
        }
        return carInfo;
    }

    private JSONObject getManInfoYt(String idNumber) {
        JSONObject result = null;
        String url = baseUrl + "/api/getDrivingLicenseAllInfo?sfzmhm=" + idNumber;
        List<NameValuePair> paramList = new ArrayList<>();
        paramList.add(new BasicNameValuePair("sfzmhm", idNumber));

        try {
            HttpEntity reqEntity = new UrlEncodedFormEntity(paramList, "utf-8");
            HttpClient client = HttpClients.createDefault();
            HttpGet get = new HttpGet(url);
            HttpResponse httpResponse = client.execute(get);
            String responseString = EntityUtils.toString(httpResponse.getEntity());
            responseString = StringEscapeUtils.unescapeJava(responseString);
            responseString = responseString.substring(1, responseString.length() - 1);
            //System.out.println(responseString);
            result = JSONObject.parseObject(responseString);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    private JSONObject getManInfoQd(String idNumber) {
        JSONObject result = null;
        String url = baseUrl + "/api/getDrivingLicenseAllInfo?sfzmhm=" + idNumber;
        List<NameValuePair> paramList = new ArrayList<>();
        paramList.add(new BasicNameValuePair("sfzmhm", idNumber));

        try {
            HttpEntity reqEntity = new UrlEncodedFormEntity(paramList, "utf-8");
            HttpClient client = HttpClients.createDefault();
            HttpGet get = new HttpGet(url);
            HttpResponse httpResponse = client.execute(get);
            String responseString = EntityUtils.toString(httpResponse.getEntity());
            result = JSONObject.parseObject(responseString);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    private JSONArray getCarListYt(String idNumber) {
        JSONArray result = null;
        String url = baseUrl + "/api/localCarHphmHpzlInfo?sfzmmc=A&sfzmhm=" + idNumber;


        try {
//            HttpEntity reqEntity = new UrlEncodedFormEntity(paramList, "utf-8");
            HttpClient client = HttpClients.createDefault();
            HttpGet get = new HttpGet(url);
            //post.setEntity(reqEntity);

            HttpResponse httpResponse = client.execute(get);
            String responseString = EntityUtils.toString(httpResponse.getEntity());
            responseString = StringEscapeUtils.unescapeJava(responseString);
            responseString = responseString.substring(1, responseString.length() - 1);

            result = JSONObject.parseArray(responseString);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    private JSONArray getCarListQd(String idNumber) {
        JSONArray result = null;
        String url = baseUrl + "/api/localCarHphmHpzlInfo?sfzmmc=A&sfzmhm=" + idNumber;


        try {
//            HttpEntity reqEntity = new UrlEncodedFormEntity(paramList, "utf-8");
            HttpClient client = HttpClients.createDefault();
            HttpGet get = new HttpGet(url);
            //post.setEntity(reqEntity);

            HttpResponse httpResponse = client.execute(get);
            String responseString = EntityUtils.toString(httpResponse.getEntity());
            result = JSONObject.parseArray(responseString);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    public String getManZt(String zt) {
        String result = "";
        if (zt != null && zt.length() > 0) {
            for (int i = 0; i < zt.length(); i++) {
                if (i > 0) {
                    result += "/";
                }
                result += getCodeName("00", "2005", zt.substring(i, i + 1));
            }
        }
        return result;
    }

    public String getCarZt(String zt) {
        String result = "";
        if (zt != null && zt.length() > 0) {
            for (int i = 0; i < zt.length(); i++) {
                if (i > 0) {
                    result += "/";
                }
                result += getCodeName("00", "1017", zt.substring(i, i + 1));
            }
        }
        return result;
    }


    private JSONObject getCarInfo(String carNumber,String carNumberType)
    {
        if("wf".equals(appDomain))
        {
            return getCarInfoWf(carNumber,carNumberType);
        }
        if("yt".equals(appDomain))
        {
            return getCarInfoYt(carNumber,carNumberType);
        }

        if("qd".equals(appDomain))
        {
            return getCarInfoQd(carNumber,carNumberType);
        }
        return null;
    }


    //烟台
    private JSONObject getCarInfoYt(String carNumber, String carNumberType) {
        JSONObject result = null;
        String url = baseUrl + "/api/localCarInfo?carNumber=鲁" + carNumber + "&carNumberType=" + carNumberType;

        try {
            HttpClient client = HttpClients.createDefault();
            HttpGet get = new HttpGet(url);
            HttpResponse httpResponse = client.execute(get);
            String responseString = EntityUtils.toString(httpResponse.getEntity());
            responseString = StringEscapeUtils.unescapeJava(responseString);
            responseString = responseString.substring(1, responseString.length() - 1);

            result = JSONObject.parseObject(responseString);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    //潍坊
    private JSONObject getCarInfoWf(String carNumber, String carNumberType) {
        JSONObject paramsJson = new JSONObject();
        paramsJson.put("hpzl", carNumberType);
        paramsJson.put("hphm", carNumber);
        JSONObject resultJson = sixInOneUtils.call(paramsJson, "01C21");

        return resultJson;
    }

    //青岛
    private JSONObject getCarInfoQd(String carNumber, String carNumberType) {
        JSONObject result = null;
        String url = baseUrl + "/api/localCarInfo?carNumber=" + carNumber + "&carNumberType=" + carNumberType;

        try {
            HttpClient client = HttpClients.createDefault();
            HttpGet get = new HttpGet(url);
            HttpResponse httpResponse = client.execute(get);
            String responseString = EntityUtils.toString(httpResponse.getEntity());

            result = JSONObject.parseObject(responseString);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping("/api/getDrivingLicenseAllInfo2")
    public String getDrivingLicenseAllInfo2(String sfzmhm) {
        return "\"{}\"";
    }


    @RequestMapping("/api/getDrivingLicenseAllInfo")
    public String getDrivingLicenseAllInfo(String sfzmhm) {
        return "\"{\n" +
                "\"sfzmmc\":\"A\",\n" +
                "\"sfzmhm\":\"379002197202267018\",\n" +
                "\"hmcd\":\"2\",\n" +
                "\"xm\":\"张涛\",\n" +
                "\"xb\":\"1\",\n" +
                "\"csrq\":\"1972-02-26 00:00:00.0\",\n" +
                "\"gj\":\"156\",\n" +
                "\"djzsxzqh\":\"370211\",\n" +
                "\"djzsxxdz\":\"山东省龙口市石良镇东竹园村216号\",\n" +
                "\"lxzsxzqh\":\"370681\",\n" +
                "\"lxzsxxdz\":\"山东省龙口市石良镇东竹园村216号\",\n" +
                "\"lxzsyzbm\":\"265707\",\n" +
                "\"lxdh\":\"8762023\",\n" +
                "\"sjhm\":\"15853512379\",\n" +
                "\"dzyx\":\"tset@qq.com\",\n" +
                "\"dabh\":\"370601564350\",\n" +
                "\"zjcx\":\"C1\",\n" +
                "\"ljjf\":\"0\",\n" +
                "\"zt\":\"BH\",\n" +
                "\"cclzrq\":\"1992-07-09 00:00:00.0\",\n" +
                "\"jzqx\":\"2\",\n" +
                "\"syrq\":\"2025-07-09 00:00:00.0\",\n" +
                "\"yxqs\":\"2015-07-09 00:00:00.0\",\n" +
                "\"yxqz\":\"2025-07-09 00:00:00.0\",\n" +
                "\"xzqh\":\"370681\",\n" +
                "\"zzzm\":null,\n" +
                "\"gxsj\":\"2017-10-26 10:49:32.0\",\n" +
                "\"zxbh\":\"3770033145005\",\n" +
                "\"fzjg\":\"鲁F\"\n" +
                "}\n\"";
    }

    @RequestMapping("/api/localCarInfo")
    public String localCarInfo(String carNumberType, String carNumber) {
        return "\"{\n" +
                "\"bdjcs\":\"0\",\n" +
                "\"bpcs\":\"0\",\n" +
                "\"bxzzrq\":\"2017-04-14 00:00:00.0\",\n" +
                "\"bzcs\":\"0\",\n" +
                "\"ccdjrq\":\"2011-04-14 10:22:09.0\",\n" +
                "\"ccrq\":\"2009-06-20 00:00:00.0\",\n" +
                "\"cllx\":\"K33\",\n" +
                "\"clly\":\"1\",\n" +
                "\"clpp1\":\"波罗牌\",\n" +
                "\"clsbdh\":\"LSVNR49JX92045220\",\n" +
                "\"clxh\":\"SVW7144CRD\",\n" +
                "\"clyt\":\"P1\",\n" +
                "\"csys\":\"B\",\n" +
                "\"cwkc\":\"4200\",\n" +
                "\"cwkg\":\"1465\",\n" +
                "\"cwkk\":\"1650\",\n" +
                "\"dabh\":\"370600468619\",\n" +
                "\"djrq\":\"2017-03-09 13:52:44.0\",\n" +
                "\"djzsbs\":\"370016901851\",\n" +
                "\"dybj\":\"0\",\n" +
                "\"e_flag\":\"1\",\n" +
                "\"fdjh\":\"124329\",\n" +
                "\"fdjrq\":\"2011-04-14 10:29:11.0\",\n" +
                "\"fdjxh\":\"CDD\",\n" +
                "\"fhgzrq\":\"2017-03-09 13:52:45.0\",\n" +
                "\"fprq\":\"2011-04-14 10:22:09.0\",\n" +
                "\"fzjg\":\"鲁F\",\n" +
                "\"fzrq\":\"2011-04-14 10:29:04.0\",\n" +
                "\"gcjk\":\"A\",\n" +
                "\"gl\":\"63\",\n" +
                "\"glbm\":\"370609000400\",\n" +
                "\"gxrq\":\"2017-03-09 15:57:20.0\",\n" +
                "\"hbdbdk\":\"GB18352.3-2005国Ⅳ\",\n" +
                "\"hdfs\":\"A\",\n" +
                "\"hdzk\":\"5\",\n" +
                "\"hgzbh\":\"WAE000901060215\",\n" +
                "\"hlj\":\"1425\",\n" +
                "\"hphm\":\"" + carNumber + "\",\n" +
                "\"hpqysj\":\"2011-04-14 10:22:09.0\",\n" +
                "\"hpzl\":\"02\",\n" +
                "\"id\":\"1355616\",\n" +
                "\"jbr\":\"高辅增\",\n" +
                "\"jyhgbzbh\":\"183706516576\",\n" +
                "\"jyw\":\"2A62080306058299F0EAF1FE6063610F0105027B6B772621163A3F4650643B57411E0400050600000000070A0A7E050B7170040808025A4671405F425816535A33304135\",\n" +
                "\"lsh\":\"1F10414016430\",\n" +
                "\"ltgg\":\"185/60 R14 82H\",\n" +
                "\"lts\":\"4\",\n" +
                "\"pl\":\"1390\",\n" +
                "\"plj\":\"1435\",\n" +
                "\"qzbfqz\":\"2099-12-31 00:00:00.0\",\n" +
                "\"rlzl\":\"A\",\n" +
                "\"sfxny\":\"2\",\n" +
                "\"sfzmhm\":\"370613198706011022\",\n" +
                "\"sfzmmc\":\"A\",\n" +
                "\"sjhm\":\"15853588615\",\n" +
                "\"syq\":\"2\",\n" +
                "\"syqsrq\":\"2011-04-14 10:22:09.0\",\n" +
                "\"syr\":\"车钰琳\",\n" +
                "\"syxz\":\"A\",\n" +
                "\"zgzl\":\"ABCDEFJ\",\n" +
                "\"xh\":\"37060011083559\",\n" +
                "\"xszbh\":\"3700008091974\",\n" +
                "\"xzqh\":\"370613\",\n" +
                "\"yqjyqz2\":\"2020-04-30 00:00:00.0\",\n" +
                "\"yqjyqzbfqz\":\"2021-04-30 00:00:00.0\",\n" +
                "\"ytsx\":\"9\",\n" +
                "\"yxqz\":\"2018-04-30 00:00:00.0\",\n" +
                "\"yzbm1\":\"264102\",\n" +
                "\"zbzl\":\"1139\",\n" +
                "\"zj\":\"2460\",\n" +
                "\"zs\":\"2\",\n" +
                "\"zsxxdz\":\"山东省烟台市莱山区莱山镇车家疃村89号\",\n" +
                "\"zsxzqh\":\"370613\",\n" +
                "\"zt\":\"B\",\n" +
                "\"zxxs\":\"1\",\n" +
                "\"zzcmc\":\"上海大众汽车有限公司\",\n" +
                "\"zzg\":\"156\",\n" +
                "\"zzl\":\"1514\",\n" +
                "\"zzxxdz\":\"山东省烟台市莱山区莱山镇车家疃村89号\",\n" +
                "\"zzxzqh\":\"370613\"}\n\"";
    }

    @RequestMapping("/api/localCarHphmHpzlInfo")
    public String localCarHphmHpzlInfo(String sfzmhm, String sfzmmc) {
        return "\"[\n" +
                "{\"hphm\":\"YC0066\",\"hpzl\":\"02\"},\n" +
                "{\"hphm\":\"Y67D98\",\"hpzl\":\"02\"},\n" +
                "{\"hphm\":\"FYY156\",\"hpzl\":\"02\"}\n" +
                "]\n\"";
    }


    @Autowired
    TjDao tjDao;


    @RequestMapping(value = "/cjg/tjxx", produces = "application/json")
    public String tjxx(String sfzmhm) {
        JSONObject paramsJson = new JSONObject();
        paramsJson.put("sfzmhm", sfzmhm);
        //JSONObject resultJson = sixInOneUtils.call(paramsJson,"02C90");
        JSONObject resultJson = new JSONObject();
        resultJson.put("sl", "1");
        if ("0".equals(resultJson.get("sl"))) {
            return resultJson.toJSONString();
        } else {
            List<Tj> tjList = tjDao.getTjInfoBySfzmhm(sfzmhm);
            if (tjList != null&&tjList.size()>0) {
                Tj tjInfo = tjList.get(0);
                JSONObject tjxxJson = JSONObject.parseObject(JSONObject.toJSONString(tjInfo));
                tjxxJson.put("sl", "1");
                return tjxxJson.toJSONString();
            } else {
                return resultJson.toJSONString();
            }
        }
    }

    @RequestMapping(value = "/cjg/manInfo", produces = "application/json")
    public String c0226(String sfzmhm) {
        long start = new Date().getTime();
        JSONObject paramJson = new JSONObject();
        paramJson.put("sfzmhm", sfzmhm);
        JSONObject resultJson = sixInOneUtils.call(paramJson, "02C26");
        long myLag = new Date().getTime() - start;
        long lag = resultJson.getLong("lag");
        long lagDiff = myLag - lag;
        JSONObject lagJson = new JSONObject();
        lagJson.put("myLag", myLag);
        lagJson.put("lagDiff", lagDiff);
        lagJson.put("lag", lag);
        resultJson.put("lagInfo", lagJson);

        return resultJson.toJSONString();

    }

    @GetMapping(value = "/pvs/verify/v1.0/{id}", produces = "application/json")
    public String demoPvsVerify(@PathVariable String id) {
        System.out.println("输入身份证号:" + id);
        return "{\n" +
                "\"code\": 0,\n" +
                "    \"message\": \"success\",\n" +
                "    \"data\": {\n" +
                "    \t\"sdry\": 0,\n" +
                "\t\t\"skry\": 0,\n" +
                "\t\t\"swry\": 0,\n" +
                "\t\t\"xsfzqkry\": 0,\n" +
                "\t\t\"zdsfry\": 0,\n" +
                "\t\t\"zszhjsbry\": 0,\n" +
                "\t\t\"ztry\": 0\n" +
                "\t} \n" +
                "}";
    }

    @RequestMapping(value = "/pvs/verify", produces = "application/json")
    public String pvsVerify(String sfzmhm, String xm, String scry, String scrymc) {


        try {
            String result = null;
            String url = pvsVerifyUrl + sfzmhm;
            try {
                HttpClient client = HttpClients.createDefault();
                HttpGet get = new HttpGet(url);
                HttpResponse httpResponse = client.execute(get);
                result = EntityUtils.toString(httpResponse.getEntity());

            } catch (Exception e) {
                e.printStackTrace();
            }


            JSONObject resultJson = JSONObject.parseObject(result);
            if ("success".equals(resultJson.getString("message"))) {
                int sdry = resultJson.getJSONObject("data").getInteger("sdry");
                int skry = resultJson.getJSONObject("data").getInteger("skry");
                int swry = resultJson.getJSONObject("data").getInteger("swry");
                int xsfzqkry = resultJson.getJSONObject("data").getInteger("xsfzqkry");
                int zdsfry = resultJson.getJSONObject("data").getInteger("zdsfry");
                int zszhjsbry = resultJson.getJSONObject("data").getInteger("zszhjsbry");
                int ztry = resultJson.getJSONObject("data").getInteger("ztry");
                if (sdry + skry + swry + xsfzqkry + zdsfry + zszhjsbry + ztry > 0) {
                    Zdryjl zdryjl = new Zdryjl();
                    zdryjl.setSfzmhm(sfzmhm);
                    zdryjl.setXm(xm);
                    zdryjl.setScry(scry);
                    zdryjl.setScrymc(scrymc);
                    String rylx = "";
                    String rylxmc = "";
                    if (sdry == 1) {
                        rylx += "1,";
                        rylxmc += "涉毒人员,";
                    }
                    if (skry == 1) {
                        rylx += "2,";
                        rylxmc += "涉恐人员,";
                    }
                    if (swry == 1) {
                        rylx += "3,";
                        rylxmc += "涉稳人员,";
                    }
                    if (xsfzqkry == 1) {
                        rylx += "4,";
                        rylxmc += "刑事犯罪前科人员,";
                    }
                    if (zdsfry == 1) {
                        rylx += "5,";
                        rylxmc += "重点上访人员,";
                    }
                    if (zszhjsbry == 1) {
                        rylx += "6,";
                        rylxmc += "肇事肇祸精神病人员,";
                    }
                    if (ztry == 1) {
                        rylx += "7,";
                        rylxmc += "在逃人员,";
                    }
                    if (rylx.length() > 0) {
                        rylx = rylx.substring(0, rylx.length() - 1);
                        rylxmc = rylxmc.substring(0, rylxmc.length() - 1);
                    }
                    zdryjl.setRylx(rylx);
                    zdryjl.setRylxmc(rylxmc);
                    zdryjlDao.saveZdryjl(zdryjl);
                }
            }
            return result;

        } catch (Exception e) {
            e.printStackTrace();
            return "{\n" +
                    "\"code\": 0,\n" +
                    "    \"message\": \"success\",\n" +
                    "    \"data\": {\n" +
                    "    \t\"sdry\": 0,\n" +
                    "\t\t\"skry\": 0,\n" +
                    "\t\t\"swry\": 0,\n" +
                    "\t\t\"xsfzqkry\": 0,\n" +
                    "\t\t\"zdsfry\": 0,\n" +
                    "\t\t\"zszhjsbry\": 0,\nxf" +
                    "\t\t\"ztry\": 0\n" +
                    "\t} \n" +
                    "}";
        }


    }
}
